﻿<%@page import="com.sinba.common.user.service.IRegisterUserService"%>
<%@page import="com.sinba.common.system.dto.SingleGroupReportStatDTO"%>
<%@page import="java.util.List"%>
<%@page import="com.sinba.common.system.service.ITransactionRecordService"%>
<%@page import="com.sinba.common.system.dto.TransactionRecordDTO"%>
<%@page import="com.sinba.common.system.service.IExtractService"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%

if(session.getAttribute("systemUser")==null){
	response.sendRedirect( "login.jsp");
	return;
}
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragrma","no-cache");
response.setDateHeader("Expires",0);


ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
//待处理的提现统计
IExtractService extractService = (IExtractService)ac.getBean("extractService");
Integer waitExtractQuy = extractService.extractCount("待受理");
request.setAttribute("waitExtractQuy",waitExtractQuy);


//今天拔出总数
//充值统计
Double rechargeSum = 0D;
ITransactionRecordService transactionRecordService = (ITransactionRecordService)ac.getBean("transactionRecordService");
TransactionRecordDTO trDTO = new TransactionRecordDTO();
trDTO.setSearchType("todaySearch");
trDTO.setDtype("Dynamic");
trDTO.setInOrExp("income");
trDTO.setTransactionTypes(new String[]{"充值"});
List<SingleGroupReportStatDTO> sgrs = transactionRecordService.statAccount(trDTO);
for(SingleGroupReportStatDTO sgr : sgrs){
	if("充值".equals(sgr.getGroupField())){
		rechargeSum = rechargeSum+sgr.getAggField();
	}
}
request.setAttribute("rechargeSum",rechargeSum);


//全部拔出总数
Double allRechargeSum = 0D;
TransactionRecordDTO trDTO1 = new TransactionRecordDTO();
trDTO1.setDtype("Dynamic");
trDTO1.setInOrExp("income");
trDTO.setTransactionTypes(new String[]{"充值"});
List<SingleGroupReportStatDTO> sgrs1 = transactionRecordService.statAccount(trDTO1);
for(SingleGroupReportStatDTO sgr : sgrs1){
	if("充值".equals(sgr.getGroupField())){
		allRechargeSum = allRechargeSum+sgr.getAggField();
	}
}
request.setAttribute("allRechargeSum",allRechargeSum);

/* //今天在线充值总数
Double payRechargeSum = 0D;
TransactionRecordDTO trDTO2 = new TransactionRecordDTO();
trDTO2.setSearchType("todaySearch");
trDTO2.setDtype("Recharge");
trDTO2.setInOrExp("income");
trDTO2.setRemark("在线充值");
List<SingleGroupReportStatDTO> sgrs2 = transactionRecordService.statAccount(trDTO2);
for(SingleGroupReportStatDTO sgr : sgrs2){
	if("充值".equals(sgr.getGroupField())){
		payRechargeSum = payRechargeSum+sgr.getAggField();
	}
}
request.setAttribute("payRechargeSum",payRechargeSum);

//全部在线充值总数
Double payAllRechargeSum = 0D;
TransactionRecordDTO trDTO3 = new TransactionRecordDTO();
trDTO3.setDtype("Recharge");
trDTO3.setInOrExp("income");
trDTO3.setRemark("在线充值");
List<SingleGroupReportStatDTO> sgrs3 = transactionRecordService.statAccount(trDTO3);
for(SingleGroupReportStatDTO sgr : sgrs3){
	if("充值".equals(sgr.getGroupField())){
		payAllRechargeSum = payAllRechargeSum+sgr.getAggField();
	}
}
request.setAttribute("payAllRechargeSum",payAllRechargeSum); */



//今天注册会员数
IRegisterUserService registerUserService = (IRegisterUserService)ac.getBean("registerUserService");
Integer todayRegSum = registerUserService.userCount(null,"TodayRegSum",null);
request.setAttribute("todayRegSum",todayRegSum);
//今天激活会员数
Integer todayActivationSum = registerUserService.userCount(null,"TodayActivationSum",null);
request.setAttribute("todayActivationSum",todayActivationSum);

//奖金发放统计
Double allDynamicSum = 0D;
Double allStaticSum = 0D;
TransactionRecordDTO trDTO4 = new TransactionRecordDTO();
trDTO4.setTransactionTypes(new String[]{"日分红","运营中心提成","小组提成","组织提成","客户提成"});
trDTO4.setInOrExp("income");
List<SingleGroupReportStatDTO> sgrs4 = transactionRecordService.statAccount(trDTO4);
for(SingleGroupReportStatDTO sgr : sgrs4){
	if("日分红".equals(sgr.getGroupField())){
		allStaticSum =  allStaticSum+sgr.getAggField();
	}else{
		allDynamicSum = allDynamicSum+sgr.getAggField();
	}
}

//今天动态
Double todayDynamicSum = 0D;
Double todayStaticSum = 0D;
trDTO4.setSearchType("todaySearch");
List<SingleGroupReportStatDTO> sgrs5 = transactionRecordService.statAccount(trDTO4);
for(SingleGroupReportStatDTO sgr : sgrs5){
	if("日分红".equals(sgr.getGroupField())){
		todayStaticSum =  todayStaticSum+sgr.getAggField();
	}else{
		todayDynamicSum = todayDynamicSum+sgr.getAggField();
	}
}

request.setAttribute("allDynamicSum",allDynamicSum);
request.setAttribute("allStaticSum",allStaticSum);
request.setAttribute("todayDynamicSum",todayDynamicSum);
request.setAttribute("todayStaticSum",todayStaticSum);
%>     
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="../scripts/jquery/jqgrid/redmond/jquery-ui-1.8.1.custom.css">
<link rel="stylesheet" type="text/css" href="../scripts/jquery/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../scripts/jquery/jqgrid/css/jqgrid.css">
<link rel="stylesheet" type="text/css" href="../scripts/jquery/easyui/themes/icon.css">
<script src="../scripts/jquery/jquery-1.4.2.min.js"></script> 
<script src="../scripts/i18n/i18n_zh_CN.js"></script>
<script type="text/javascript" src="../scripts/jquery/jquery-ui-1.8.2.custom/js/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript" src="../scripts/jquery/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../scripts/jquery/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../scripts/jquery/jqgrid/js/jqGrid.js"></script>
<script type="text/javascript" src="../scripts/jquery/jquery-json.js"></script>
<script type="text/javascript" src="../scripts/jquery/ajaxfileupload/ajaxfileupload.js"></script>
<script type="text/javascript" src="../scripts/core/package.js"></script>
<script type="text/javascript" src="../scripts/core/import.js"></script>
<script src="../scripts/itsm/common/utility/tabUtility.js?random=${currentTime}"></script>
<script src="../scripts/jqgrid_common.js"></script>
<script src="../scripts/easyui_common.js"></script>
<script src="../scripts/jquery_common.js"></script>
<script src="../scripts/jquery/ckeditor/ckeditor.js"></script>
<script src="../scripts/jquery/editor/xheditor-1.1.12-zh_CN.min.js"></script>
<script src="../scripts/itsm/common/initEditor.js"></script>
<title>后台管理</title>
<style type="text/css">
a{
	text-decoration:none;
	color:black;
}
a:link{
	text-decoration:none;
	color:black;
}
a:visited{
	text-decoration:none;
	color:black;
}
a:hover{
	text-decoration:none;
	color:black;
}
a:active{
	text-decoration:none;
	color:black;
}
</style>
<script>
$(function(){
	$('#loginOut_a').click(function(){
		$.messager.confirm('温馨提示', '<br/>'+'您确定要退出系统吗？', function(r){
			if (r)
			{
				window.location='logout.jsp';
			}
		});
	});
	itsm.common.utility.tabUtility.addTab('我的首页','main.jsp');
});

function systemPawwordWinOpen(){
	$('#systemPasswordWin').window('open');
}
//会员登录
function userLogin(loginName){
	$.post('user!userLogin.action','userDTO.systemPassword='+$('#systemAdminPassword').val()+'&userDTO.loginName='+loginName,function(data){
		if(data)
			window.location.reload();
		else
			alert('登录失败');
	})
}


function optPawwordWinOpen(){
	$('#optPasswordWin').window('open');
}
function userOptLogin(loginName){
	$.post('user!userLogin.action','userDTO.systemPassword='+$('#optPassword').val()+'&userDTO.loginName='+loginName,function(data){
		if(data){
			$('#optPasswordWin').window('close');
			itsm.common.utility.tabUtility.addTab('拆分日志','business/autoSplit.jsp')
		}else{
			alert('登录失败');
		}
			
	})
}

//初始化数据
function ininSystemData(){
	$.messager.confirm('系统提示', '<br/>'+'您确定在初始化系统数据吗？', function(r){
		if (r)
		{
			$.post('registerUser!initSystemData.action',function(){
				alert('初始化成功!');
				window.location.reload();
			});
		}
	});
}

</script>
</head>
<body class="easyui-layout">
	<div region="west" split="true" title="欢迎:${systemUser.loginName}" style="width:200px;padding1:1px;overflow:hidden;">
		<div class="easyui-accordion" fit="true" border="false">
		
			<div title="会员管理" selected="true"  style="padding:10px;">
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('会员管理','user/registerUserMain.jsp')">会员管理</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('验证码列表','system/emailAuthMain.jsp')">验证码列表</a><br><br>	
				<c:if test="${systemUser.userRole eq 'admin1' or systemUser.userRole eq 'admin2'}">
					<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('团队业绩','system/teamyeji.jsp')">团队业绩</a><br><br>
				</c:if>
			</div>
			<c:if test="${systemUser.userRole eq 'admin1'}">
			
			<div title="交易管理"  style="padding:10px;">
				<!-- <a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('EP交易记录','system/buyMain.jsp')">EP交易记录</a><br><br> -->
				
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('排队买入列表','business/buyIng.jsp')">排队买入列表</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('排队卖出列表','business/sellIng.jsp')">排队卖出列表</a><br><br>
				
				<!-- <a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('匹配列表(所有)','business/match.jsp')">成功匹配列表</a><br><br> -->
				
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('买入列表','business/buy.jsp')">买入列表</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('卖出列表','business/sell.jsp')">卖出列表</a><br><br>
				<a style="cursor:pointer" onClick="javascript:optPawwordWinOpen()">拆分日志</a><br><br>
				<a style="cursor:pointer" href="business/autoMatch.jsp" target="_blank">自动匹配</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('数据统计','business/dataStat.jsp')" target="_blank">数据统计</a><br><br>
			</div> 
			
			<c:if test="${systemUser.systemSign eq 'YES'}" >
			<div title="财务管理" style="padding:10px;">
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('会员充值','system/userRecharge.jsp')">会员充值</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('会员现金银行余额','system/statDynamicAccountBalance.jsp')">会员现金银行余额</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('交易记录','system/transMain.jsp')">交易记录</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('提现申请','system/extractMain.jsp')">提现申请</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('静态分红','system/staticHongMain.jsp')">静态分红</a><br><br>
				
			</div>
			</c:if>
			<div title="辅助管理" style="padding:10px;">
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('在线支付记录','system/orderMain.jsp')">在线支付记录</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('验证码列表','system/emailAuthMain.jsp')">验证码列表</a><br><br>				
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('激活码列表','system/registerCodeList.jsp')">激活码列表</a><br><br>		
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('站内留言','system/systemMessage.jsp')">站内留言</a><br><br>
			</div>
			</c:if>
			<!--  
			<c:if test="${systemUser.systemSign eq 'YES'}" >
			<div title="交易大厅" style="padding:10px;">
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('投资级别','system/investmentLevelMain.jsp')">投资级别</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('交易规则','system/ruleMain.jsp')">交易规则</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('交易记录','system/transMain.jsp')">交易记录</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('挂牌卖出','system/sellMain.jsp')">挂牌卖出</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('拆分日志','system/splitMain.jsp')">拆分日志</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('自动回购','system/autoBackBuy.jsp')">自动回购</a>
			</div>
			</c:if>-->
			<c:if test="${systemUser.userRole eq 'admin1'}">
			<div title="网站管理" style="padding:10px;">
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.refreshTab('编辑内容','news!findNewsByNewType.action?newsQueryDTO.newType=CompanyProfile')">公司简介</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.refreshTab('编辑内容','news!findNewsByNewType.action?newsQueryDTO.newType=ContactUS')">联系我们</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.refreshTab('编辑内容','news!findNewsByNewType.action?newsQueryDTO.newType=Rule')">理财规则</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.refreshTab('编辑内容','news!findNewsByNewType.action?newsQueryDTO.newType=CorporateCulture')">企业文化</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.refreshTab('新闻管理','news/newsMain.jsp?newType=WebAffiche')">公告栏</a><br><br>
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.refreshTab('新闻管理','news/newsMain.jsp?newType=WebNews')">站内新闻</a><br><br> 
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.refreshTab('文件上传','news/fileUpload.jsp')">文件上传</a><br><br> 
				<c:if test="${systemUser.systemSign eq 'YES'}" >
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('平台设置','system/ruleset.jsp')">平台设置</a><br><br>
				</c:if>
				<!--  
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('栏目管理','news/topicMain.jsp')">栏目管理</a><br><br> 
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('分类管理','news/categoryMain.jsp')">分类管理</a><br><br> 
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('内容管理','news/newsMain.jsp')">内容管理</a> -->
			</div>
			<c:if test="${systemUser.systemSign eq 'YES'}" >
			<div title="系统设置" style="padding:10px;">
				<a style="cursor:pointer" onClick="ininSystemData();">初始化数据</a><br><br> 
				<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('用户管理','user/userMain.jsp')">用户管理</a> 
			</div>
			</c:if>
			</c:if>
		</div>
	</div>
	<div region="center" id="regCenter" title="后台管理--<a style='cursor:pointer' href='javascript:itsm.common.utility.tabUtility.refreshWindow()'>[点击刷新]</a>--<A href='javascript:systemPawwordWinOpen()'>[管理]</A>--<a id='loginOut_a' href='#'>[X注销]</a>">
		<div class="easyui-tabs" fit="true" border="false" id="itsmMainTab">
			<%-- <div title="我的首页" >
				<div style="padding: 20px; font-size: 18px;">
					<hr>
					<b>待处理：</b><br>
					<a style="cursor:pointer" onClick="javascript:itsm.common.utility.tabUtility.addTab('提现申请','system/extractMain.jsp')">提现申请(${waitExtractQuy })</a><br><br>
					<hr>
					<b>会员相关统计：</b><br>
					今天注册会员数：${todayRegSum }<br>
					今天激活会员数：${ todayActivationSum }<br>
					<br>
					<hr>
					<b>拔币相关统计：</b><br>
					今天拔出总数：<fmt:formatNumber value="${rechargeSum}" pattern="#0.0000"/><br>
					全部拔出总数：<fmt:formatNumber value="${allRechargeSum}" pattern="#0.0000"/><br>
					<br>
					今天在线充值总数：<fmt:formatNumber value="${payRechargeSum}" pattern="#0.0000"/><br>
					全部在线充值总数：<fmt:formatNumber value="${payAllRechargeSum}" pattern="#0.0000"/><br>
					<br>
					<hr>
					
					<b>奖金发放统计：</b><br>
					今天发放奖金总数：
					动态：<fmt:formatNumber value="${todayDynamicSum*0.7}" pattern="#0.0000"/>+
					日分红：<fmt:formatNumber value="${todayStaticSum*0.7}" pattern="#0.0000"/>+
					循环投资：<fmt:formatNumber value="${(todayDynamicSum+todayStaticSum)*0.3}" pattern="#0.0000"/>=
					<fmt:formatNumber value="${(todayDynamicSum+todayStaticSum)}" pattern="#0.0000"/>
					<br>
					全部奖金发放总数：
					动态：<fmt:formatNumber value="${allDynamicSum*0.7}" pattern="#0.0000"/>+
					日分红：<fmt:formatNumber value="${allStaticSum*0.7}" pattern="#0.0000"/>+
					循环投资：<fmt:formatNumber value="${(allDynamicSum+allStaticSum)*0.3}" pattern="#0.0000"/>=
					<fmt:formatNumber value="${(allDynamicSum+allStaticSum)}" pattern="#0.0000"/>
					<br>
					<hr>
					<b>奖金占充值总比例：</b><br>
					今天：
					<c:if test="${rechargeSum>0}">
					<fmt:formatNumber value="${(todayDynamicSum+todayStaticSum)/0.7/rechargeSum*100}" pattern="#0.0000"/>%
					</c:if>
					<c:if test="${rechargeSum==0}">
						今天充值：0
					</c:if>
					<br>
					<c:if test="${allRechargeSum>0}">
					总：<fmt:formatNumber value="${(allDynamicSum+allStaticSum)/0.7/allRechargeSum*100}" pattern="#0.0000"/>%
					</c:if>
					<c:if test="${allRechargeSum==0}">
					充值：0
					</c:if>
					<hr>
				</div>
			</div> --%>
		</div>
	</div>
	
	<%--系统错误提示框--%>
	<div id="systemErrorWin" title="<fmt:message key="msg.tips" />" class="easyui-window" closed="true" collapsible="false" minimizable="false" maximizable="true" modal="false"  style="width:300px;height:155px;">
		<div style="padding:3px;" id="systemErrorInfo" ></div>
	</div>
	
	<%--管理员密码--%>
	<div id="systemPasswordWin" title="管理员密码" class="easyui-window" closed="true" collapsible="false" minimizable="false" maximizable="true" modal="false"  style="width:300px;height:120px;padding: 10px;">
		<input type="password" id="systemAdminPassword" >
		<br><br>
		<a onclick="userLogin('${systemUser.loginName}')" class="easyui-linkbutton"  plain="true">确定</a>
	</div>
	
	<%--操作密码--%>
	<div id="optPasswordWin" title="操作密码" class="easyui-window" closed="true" collapsible="false" minimizable="false" maximizable="true" modal="false"  style="width:300px;height:120px;padding: 10px;">
		<input type="password" id="optPassword" >
		<br><br>
		<a onclick="userOptLogin('${systemUser.loginName}')" class="easyui-linkbutton"  plain="true">确定</a>
	</div>
	
	<script type="text/javascript">
	
	$(document).ajaxError(function(e, xhr, settings, exception) {
		if(xhr.status==606){
				alert('系统会话超时，请重新登录!');
				setTimeout(function(){
					location.reload();
				},2000);
		}
		if(xhr.status==403){
			alert('无权访问此页面!');
		};
		if(xhr.status==404){
			alert('页面找不到!');
			//location.reload();//404也刷新页面
		};
		if(xhr.status==500){
			alert('系统内部错误,请联系管理员!');
		};
	});
	</script>
</body>
</html>